﻿namespace Cellfish.Toolbox.Core
{
    using System;

    internal static class EqualityUtility
    {
        private const int PrimeNumber = 421;

        public static int GetHashCode(params int[] hashCodes)
        {
            if (hashCodes == null || hashCodes.Length == 0)
            {
                return 0;
            }

            var hashCode = hashCodes[0];
            for (int i = 1; i < hashCodes.Length; i++)
            {
                hashCode = (hashCode * PrimeNumber) ^ hashCodes[i];
            }

            return hashCode;
        }

        public static bool Equals<T>(T obj, object other, Func<T, T, bool> equals)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }

            if (ReferenceEquals(obj, other))
            {
                return true;
            }

            if (obj.GetType() != other.GetType())
            {
                return false;
            }

            return equals(obj, (T)other);
        }
    }
}